package gomz.pres;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * Diese Klasse erstellt das Login-GUI
 * 
 * @author Dilji
 */

public class GUILogin extends JFrame {

	// Main Panel
	private JPanel plGuiMain;

	// all the variables for main panels
	private JLabel lbLtitle;
	private JLabel lbLuser;
	private JTextField tfLuser;
	private JLabel lbLpw;
	private JPasswordField pfLpw;
	private JButton btLok;
	private JButton btLcan;
	private JButton btLreg;
	private ImageIcon imgYiChing;
	private ImageIcon imgloginLeft;
	private JLabel lbloginLeft;

	/**
	 * Konstruktor des Login-GUI erstellt und platziert die Komponenten
	 */
	protected GUILogin() {

		// set Windows Look&Feel
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}

		// Main Panel
		this.setTitle("Yi Ching Login");
		this.setVisible(true);
		this.setSize(new Dimension(580, 260));
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(GUILogin.class.getResource("/gomz/img/logo.png")));
		// set window at center of screen
		this.setLocationRelativeTo(null);

		this.plGuiMain = new JPanel();
		this.getContentPane().add(plGuiMain, BorderLayout.CENTER);
		this.plGuiMain.setBackground(GUIMain.getBgblue());
		this.plGuiMain.setBorder(BorderFactory.createEmptyBorder((GUIMain.getAbstand()), (GUIMain.getAbstand()*2), (GUIMain.getAbstand()*2), (GUIMain.getAbstand()*2)));

		// initialize the components
		this.lbLtitle = new JLabel();
		this.imgYiChing = new ImageIcon(getClass().getResource("/gomz/img/yiChing.png"));
		this.lbLtitle.setIcon(imgYiChing);
		this.lbLuser = new JLabel("Benutzername:");
		this.tfLuser = new JTextField();
		this.lbLpw = new JLabel("Passwort:");
		this.pfLpw = new JPasswordField();
		this.btLok = new JButton("OK");
		getRootPane().setDefaultButton(btLok);
		this.btLcan = new JButton("Abbrechen");
		this.btLreg = new JButton("Registrieren");
		this.lbloginLeft = new JLabel();
		this.imgloginLeft = new ImageIcon(getClass().getResource("/gomz/img/login_left.png"));
		this.imgloginLeft.setImage(this.imgloginLeft.getImage().getScaledInstance(140,140, Image.SCALE_DEFAULT));
		this.lbloginLeft.setIcon(imgloginLeft);
		
		this.tfLuser.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.pfLpw.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfLuser.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfLuser.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfLpw.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfLpw.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		
		// size of buttons
		this.btLok.setPreferredSize(new Dimension(GUIMain.getBtwidth() - 35, GUIMain.getBtheight()));
		this.btLok.setMaximumSize(new Dimension(GUIMain.getBtwidth() - 35,
				GUIMain.getBtheight()));
		this.btLcan.setPreferredSize(new Dimension(GUIMain.getBtwidth() - 35,
				GUIMain.getBtheight()));
		this.btLcan.setMaximumSize(new Dimension(GUIMain.getBtwidth() - 35,
				GUIMain.getBtheight()));
		this.btLreg.setPreferredSize(new Dimension(GUIMain.getBtwidth() - 35,
				GUIMain.getBtheight()));
		this.btLreg.setMaximumSize(new Dimension(GUIMain.getBtwidth() - 35,
				GUIMain.getBtheight()));

		// BOX fuer ok und cancel button
		Box btLbox = Box.createHorizontalBox();
		btLbox.add(btLok);
		btLbox.add(Box.createHorizontalStrut((GUIMain.getAbstand() / 2)));
		btLbox.add(btLcan);

		// BOX fuer registieren button
		Box regBox = Box.createHorizontalBox();
		regBox.add(Box.createHorizontalStrut((GUIMain.getAbstand())));
		regBox.add(btLreg);
		
		// position of components
		this.plGuiMain.setLayout(new GridBagLayout());
		GridBagConstraints cl = new GridBagConstraints();
		cl.fill = GridBagConstraints.HORIZONTAL;
		cl.insets = new Insets(0, (GUIMain.getAbstand() / 2), 0, GUIMain.getAbstand() / 2);
		
		cl.anchor = GridBagConstraints.SOUTH; // Ausrichtung oben
		cl.gridx = 0; // Spalte 1
		cl.gridy = 0; // Zeile 1
		cl.gridheight = 3;
		plGuiMain.add(lbloginLeft, cl); // Bild alle Hex
		cl.anchor = GridBagConstraints.CENTER; // Ausrichtung oben
		cl.insets = new Insets(0, (GUIMain.getAbstand() * 2), 0, GUIMain.getAbstand() / 2);
		cl.gridx = 1; // Spalte 2
		cl.gridy = 0; // Zeile 1
		cl.gridheight = 1;
		cl.gridwidth = 2;
		plGuiMain.add(lbLtitle, cl); // label Titel
		cl.gridx = 2; // Spalte 3
		cl.gridy = 0; // Zeile 1
		cl.gridwidth = 1;
		// plGuiMain.add(, cl); // Com
		cl.gridx = 3; // Spalte 4
		cl.gridy = 0; // Zeile 1
		//plGuiMain.add(, cl); // Leer

		cl.insets = new Insets(GUIMain.getAbstand(), (GUIMain.getAbstand() * 2 + 10), 0, GUIMain.getAbstand() / 2);
		cl.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben
		cl.gridheight = 1;
		cl.gridx = 0; // Spalte 1
		cl.gridy = 1; // Zeile 2
		//plGuiMain.add(, cl); // Leer
		cl.gridx = 1; // Spalte 2
		cl.gridy = 1; // Zeile 2
		plGuiMain.add(lbLuser, cl); // Label Benutzername
		cl.insets = new Insets(GUIMain.getAbstand(), (GUIMain.getAbstand() / 2), 0, GUIMain.getAbstand() / 2);
		cl.gridx = 2; // Spalte 3
		cl.gridy = 1; // Zeile 2
		cl.gridwidth = 2;
		plGuiMain.add(tfLuser, cl); // TextField Benutzername
		cl.gridx = 3; // Spalte 4
		cl.gridy = 1; // Zeile 2
		cl.gridwidth = 1;
		//plGuiMain.add(, cl); // Leer

		cl.insets = new Insets(GUIMain.getAbstand(), (GUIMain.getAbstand() * 2 + 10), 0, GUIMain.getAbstand() / 2);
		cl.gridx = 0; // Spalte 1
		cl.gridy = 2; // Zeile 3
		// plGuiMain.add(, cl); // Com
		cl.gridx = 1; // Spalte 2
		cl.gridy = 2; // Zeile 3
		plGuiMain.add(lbLpw, cl); // Label Passwort
		cl.insets = new Insets(GUIMain.getAbstand(), (GUIMain.getAbstand() / 2), 0, GUIMain.getAbstand() / 2);
		cl.gridx = 2; // Spalte 3
		cl.gridy = 2; // Zeile 3
		cl.gridwidth = 2;
		plGuiMain.add(pfLpw, cl); // PasswordField Passwort
		cl.gridx = 3; // Spalte 4
		cl.gridy = 2; // Zeile 3
		cl.gridwidth = 1;
		//plGuiMain.add(, cl); // Leer
		

		cl.gridx = 0; // Spalte 1
		cl.gridy = 3; // Zeile 4
		plGuiMain.add(regBox, cl); // Button Registrieren
		cl.gridx = 1; // Spalte 2
		cl.gridy = 3; // Zeile 4
		//plGuiMain.add(btLok, cl); // Leer
		cl.gridx = 2; // Spalte 3
		cl.gridy = 3; // Zeile 4
		plGuiMain.add(btLbox, cl); // Button Ok und Cancel
		cl.gridx = 3; // Spalte 4
		cl.gridy = 3; // Zeile 4
		//plGuiMain.add(, cl); // Leer

		this.pack();
		this.setVisible(true);

	}

	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************

	public JPanel getPlGuiMain() {
		return plGuiMain;
	}

	public void setPlGuiMain(JPanel plGuiMain) {
		this.plGuiMain = plGuiMain;
	}

	public JLabel getLbLtitle() {
		return lbLtitle;
	}

	public void setLbLtitle(JLabel lbLtitle) {
		this.lbLtitle = lbLtitle;
	}

	public JLabel getLbLuser() {
		return lbLuser;
	}

	public void setLbLuser(JLabel lbLuser) {
		this.lbLuser = lbLuser;
	}

	public JTextField getTfLuser() {
		return tfLuser;
	}

	public void setTfLuser(JTextField tfLuser) {
		this.tfLuser = tfLuser;
	}

	public JLabel getLbLpw() {
		return lbLpw;
	}

	public void setLbLpw(JLabel lbLpw) {
		this.lbLpw = lbLpw;
	}

	public JPasswordField getPfLpw() {
		return pfLpw;
	}

	public void setPfLpw(JPasswordField pfLpw) {
		this.pfLpw = pfLpw;
	}

	public JButton getBtLok() {
		return btLok;
	}

	public void setBtLok(JButton btLok) {
		this.btLok = btLok;
	}

	public JButton getBtLcan() {
		return btLcan;
	}

	public void setBtLcan(JButton btLcan) {
		this.btLcan = btLcan;
	}

	public JButton getBtLreg() {
		return btLreg;
	}

	public void setBtLreg(JButton btLreg) {
		this.btLreg = btLreg;
	}

}
